import { getAreaObj, regularRule } from '@/utils/util'
import {configToSearch,toSearchHandle} from '@/views/datacenter/business/utils/index'
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '姓名', prop: 'name' },
		{ label: '证件号码', prop: 'idCard',plusXing: '2,2' },
		{ label: '联系方式', prop: 'phone',plusXing: '5,2' },
		{ 
			label: '能力等级',
			prop: 'abilityLevel',
			propName:'abilityLevelLabel',
			code:'ACCESS_LEVEL_COUNTRY',
			api:'getDictItemList',
			type:'remoteSelect'
		},
		{ label: '诊断人', prop: 'diagnoseName' },
		{ label: '诊断单位', prop: 'diagnoseUnitName' },
		{
			label: '诊断时间',
			prop: 'diagnoseDate',
		},
		{ label: '诊断结论', prop: 'diagnoseConclusion' },
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0,type:'danger' },
				{ label: '是', value: 1,type:'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 详情
export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{
			type: 'DividerHtml',
			position: 'center',
			modelValue: '基础信息',
			span: 24,
		},
		{
			label: '姓名',
			prop: 'name',
			span: 8,
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入姓名' }],
		},
		{
			label: '证件类型',
			prop: 'voucherType',
			propName: 'voucherTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			changeField: true,
			rules: [{ required: true, message: '请选择证件类型' }],
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 8,
			changeField: true,
			rules: [{ required: true, message: '请输入证件号码' }],
		},
		{
			label: '联系方式',
			prop: 'phone',
			type: 'input',
			span: 8,
			changeField: true,
			rules: [{ pattern: regularRule.phone, message: '请输入正确的联系电话' }],
		},
		{
			label: '户籍地区',
			prop: 'crAreas',
			propName: 'cr_areas',
			type: 'AplidAreaSelect',
			changeField: true,
			rules: [{ required: true, message: '请选择户籍地区' }],
			span: 8,
		},
		{
			label: '户籍地址',
			prop: 'crAddress',
			maxlength: '140',
			showWordLimit: true,
			changeField: true,
			type: 'text',
			rules: [{ required: true, message: '请输入户籍地址' }],
			span: 8,
		},
		{
			label: '能力等级',
			prop: 'abilityLevel',
			propName: 'abilityLevelLabel',
			type: 'remoteSelect',
			code: 'ACCESS_LEVEL_COUNTRY',
			api: 'getDictItemList',
			filterKey: 'value',
			changeField: true,
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择能力等级' }],
		},
		{
			label: '诊断人姓名',
			prop: 'diagnoseName',
			span: 8,
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入诊断人姓名' }],
		},
		{
			label: '诊断人单位名称',
			prop: 'diagnoseUnitName',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入诊断人单位名称' }],
		},
		{
			label: '诊断日期',
			prop: 'diagnoseDate',
			span: 8,
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
		},
		{
			label: '养老方式',
			prop: 'provideWay',
			propName: 'provideWayLabel',
			span: 8,
			type: 'remoteSelect',
			code:'SENIOR_LIVING',
			api:'getDictItemList',
		},
		{
			label: '居住地区',
			prop: 'areas',
			propName: 'areas_name',
			type: 'AplidAreaSelect',
			changeField: true,
			rules: [{ required: true, message: '请选择居住地区' }],
			span: 8,
		},
		{
			label: '居住地址',
			prop: 'address',
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入居住地址' }],
			span: 8,
		},
		{
			label: '入住机构名称',
			prop: 'organizationName',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '入住机构统一信用代码',
			prop: 'creditCode',
			span: 8,
			maxlength: '18',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '入住机构楼栋名称',
			prop: 'buildingName',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '入住机构所在楼层',
			prop: 'floor',
			span: 8,
			append: '（层）',
			type: 'input',
		},
		{
			label: '入住机构房间号',
			prop: 'roomNumber',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '入住机构床位号',
			prop: 'bedNumber',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},

		{
			type: 'DividerHtml',
			position: 'center',
			modelValue: '健康诊断内容',
			span: 24,
		},
		{
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			label: '本次诊断结论',
			prop: 'diagnoseConclusion',
			span: 8,
		},
		{
			label: '过敏物',
			prop: 'allergyThing',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '症状描述',
			prop: 'symptomDescription',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 8,
		},
		{
			label: '用药时间段',
			prop: 'medicationTime',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 8,
		},
		{
			label: '用药描述',
			prop: 'medicationDescription',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 8,
		},
		{
			label: '体征数据',
			prop: 'bodyData',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 8,
		},
		{
			label: '备注',
			prop: 'remark',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			span: 8,
		},
	],
}

export const formConfig = {
	...detailConfig,
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '150px',
}
const moreSearchConfig:any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column:[
		...configToSearch(formConfig.column)
	]
}
export const baseConfig = {
	pageName: '健康档案',
	dictcodes: ['ACCESS_LEVEL_COUNTRY','ID_CARD_TYPE','SENIOR_LIVING'],
	addLabel: '新增',
	rowKey: 'id',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	api: {
		moreSearch:'view_dpHealthBasicsArchives_search',
		index: 'view_dpHealthBasicsArchives_page',
		add: 'view_dpHealthBasicsArchives_add',
		edit: 'view_dpHealthBasicsArchives_edit',
		import: 'view_dpHealthBasicsArchives_import',
		export: 'view_dpHealthBasicsArchives_export',
		delete: 'view_dpHealthBasicsArchives_del',
		detail: 'view_dpHealthBasicsArchives_view',
	},
	auth: {
		index: 'view_dpHealthBasicsArchives_page',
		// add: 'view_dpHealthBasicsArchives_add',
		// edit: 'view_dpHealthBasicsArchives_edit',
		// import: 'view_dpHealthBasicsArchives_import',
		// export: 'view_dpHealthBasicsArchives_export',
		delete: 'view_dpHealthBasicsArchives_del',
		detail: 'view_dpHealthBasicsArchives_view',
		mulitSet: 'mulitSet',
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看详情',
			type: 'primary',
			operate: 'detail',
			auth: 'view_dpHealthBasicsArchives_page',
			text: true,
			show: true,
		},
		// {
		// 	icon: 'editor',
		// 	label: '编辑',
		// 	type: 'primary',
		// 	operate: 'edit',
		// 	auth: 'view_dpHealthBasicsArchives_edit',
		// 	text: true,
		// 	show: true,
		// },
	],
	paramsObj: {
		code: 2025,
	},
	dialogConfig: {
		width: '80%',
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '证件号码', prop: 'idCard', type: 'input', span: 6 },
			{ label: '姓名', prop: 'name', type: 'input', span: 6 },
			{ label: '联系方式', prop: 'phone', type: 'input', span: 6 },
			{ label: '诊断单位', prop: 'diagnoseUnitName', type: 'input', span: 6 },
			{ label: '诊断人', prop: 'diagnoseName', type: 'input', span: 6 },
			{ label: '诊断结论', prop: 'diagnoseConclusion', type: 'input', span: 6 },
			{
				label: '诊断日期',
				prop: 'diagnoseDate',
				span: 6,
				type: 'date',
				changeField: true,
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
			},
			{
				label: '能力等级',
				prop: 'abilityLevel',
				type: 'remoteSelect',
				code: 'ACCESS_LEVEL_COUNTRY',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},
	tableConfig,
	detailConfig,
	formConfig,
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig,{},params)
		return Promise.resolve({
			...params,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const crAreas: any = getAreaObj(item, 'cr', 'get')
			const areas: any = getAreaObj(item, '', 'get')

			return {
				...item,
				crAreas: crAreas.areaIds,
				cr_areas: crAreas.names,
				areas: areas.areaIds,
				areas_name: areas.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form.areas)
			const areaNameObj: any = getAreaObj(form.areas_name)

			const crAreasObj: any = getAreaObj(form.crAreas, 'cr')
			const crAreasNameObj: any = getAreaObj(form.cr_areas, 'cr')
			resolve({
				...form,
				...areaObj,
				...areaNameObj,
				...crAreasObj,
				...crAreasNameObj,
				crAreas: undefined,
				cr_areas: undefined,
				areas: undefined,
				areas_name: undefined,
			})
		})
	},
}
